using System.Collections.Generic;
using UnityEngine;

public class Fri_ship : Fri_AIController
{
	public List<WeaponFight> weaponlist;

	private float intertime;

	public bool canFight;

	public Transform takeoffstart;

	public Transform takeoffend;

	public bool ismujian;

	private float timecheck;

	private Fri_AIController temp_ai;

	private Fri_plane tempaiplane;

	private void Start()
	{
		init_ship();
	}

	public void init_ship()
	{
		if (isinit)
		{
			return;
		}
		m_transform = base.transform;
		maincam = plane_smothfollow.instance.mainCam;
		lowhpsmoke = null;
		explosionobj = null;
		if (canFight)
		{
			for (int i = 0; i < weaponlist.Count; i++)
			{
				weaponlist[i].isfriendweapon = true;
				weaponlist[i].parent_num = TypeIndex;
			}
		}
		isinit = true;
	}

	public void init_info(Attribute curatt)
	{
		isdie = false;
		Cur_att = curatt;
		bool flag = false;
		flag = ((weaponlist.Count > 3) ? true : false);
		for (int i = 0; i < weaponlist.Count; i++)
		{
			if (weaponlist[i].ismachinegun)
			{
				if (flag)
				{
					weaponlist[i].hurtdamage = curatt.curweapon.machgun / 4;
				}
				else
				{
					weaponlist[i].hurtdamage = curatt.curweapon.machgun / 2;
				}
				weaponlist[i].penetrationVal = curatt.curweapon.machgun_pen;
			}
			else
			{
				weaponlist[i].hurtdamage = curatt.curweapon.missile;
				weaponlist[i].penetrationVal = curatt.curweapon.missile_pen;
			}
		}
		health_con.set_heal(curatt.curhealatt);
	}

	public override void Reset_Fri_AI()
	{
		base.Reset_Fri_AI();
		init_ship();
		init_info(Cur_att);
		changeHP();
	}

	private void Update()
	{
		if (isdie)
		{
			diedfun();
			diedmove();
			return;
		}
		findTarget();
		if (ismujian)
		{
			timecheck += Time.deltaTime;
			if (timecheck > 1.5f)
			{
				Check_plane();
				timecheck = 0f;
			}
		}
		if (!canFight)
		{
			return;
		}
		intertime += Time.deltaTime;
		if (!(intertime > 2f))
		{
			return;
		}
		intertime = 0f;
		if (!(targetTra != null))
		{
			return;
		}
		if (Vector3.Distance(m_transform.position, targetTra.position) < FightDistance * 2f)
		{
			for (int i = 0; i < weaponlist.Count; i++)
			{
				weaponlist[i].fighttarget = targetTra;
				weaponlist[i].target_ai = targetAI;
			}
		}
		else
		{
			for (int j = 0; j < weaponlist.Count; j++)
			{
				weaponlist[j].fighttarget = null;
				weaponlist[j].target_ai = null;
			}
		}
	}

	public void diedmove()
	{
		MonoBehaviour.print("fri ship died move");
		if (diedtime > 3f)
		{
			diedtime = 6f;
		}
		m_transform.Translate(0f, Time.deltaTime * -20f, 0f);
	}

	public void Check_plane()
	{
		temp_ai = null;
		temp_ai = FriendPool.instance.ship_creat_plane();
		if (temp_ai != null)
		{
			tempaiplane = temp_ai.gameObject.GetComponent<Fri_plane>();
			tempaiplane.take_off(takeoffstart.position, takeoffend.position);
		}
	}
}
